package com.loong.mapper;

import com.loong.pojo.User;
import org.apache.ibatis.annotations.*;


/**
 * 负责用户模块数据库访问的接口
 */

public interface UserMapper {
    /**
     * 根据用户名查询用户信息
     * @param username 用户名
     * @return 用户信息
     */
    @Select("SELECT * FROM user WHERE username = #{username}")
    User selectUserByUsername(String username);
    /**
     * 插入用户信息
     * @param user 用户信息
     * @return 插入结果
     */
    @Insert("INSERT INTO user (username, password, email, sex, status, code, role) "
            + "VALUES (#{username}, #{password}, #{email}, #{sex}, #{status}, #{code}, #{role})")
    @Options(useGeneratedKeys = true, keyProperty = "uid")
    int insertUser(User user);

    /**
     * 根据用户激活码查询用户信息
     * @param code 激活码
     * @return 用户信息
     */
    @Select("SELECT * FROM user WHERE code = #{code}" )
    User selectUserByCode(String code);

    /**
     * 更新用户状态
     * @param uid 用户id
     * @return 更新结果
     */
    @Update("UPDATE user SET status = 1 WHERE uid = #{uid}" )
    int updateUserStatusByUid(int uid);
}
